package com.itboye.ihomebank.homefragment;

import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.PersonDataBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.XImageLoader;

public class ActivityFuYongOne extends BaseOtherActivity implements Observer {

	UserPresenter userPresenter;
	ImageView head;
	TextView name, phone;
	EditText edit_money;
	Button ok;
	private PersonDataBean dataBean;
	private String headImg;
	private String money;
	private String mobile;
	public static ActivityFuYongOne context;
	public static ActivityFuYongOne getContext() {
		return context;
	}

	public static void setContext(ActivityFuYongOne context) {
		ActivityFuYongOne.context = context;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.ok:
			String money = edit_money.getText().toString();
			if (money.equals("")) {
				ByAlert.alert("请输入转账金额");
				return;
			}
			Intent intent = new Intent(this, FuYongTwo.class);
			intent.putExtra("money", money);
			intent.putExtra("phone", mobile);
			startActivity(intent);
			break;
		case R.id.close_icon:
			finish();
			break;
		default:
			break;
		}
	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_fuyongone;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		// TODO Auto-generated method stub
		context=this;
		money = getIntent().getStringExtra("money");
		userPresenter = new UserPresenter(this);
		mobile=getIntent().getStringExtra("phone");
		userPresenter.queryUserByPhone(mobile);
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == UserPresenter.queryUserByPhone_success) {
				dataBean = (PersonDataBean) entity.getData();
				if (dataBean != null) {
					headImg = dataBean.getHead();
					XImageLoader.load(headImg, head);
					mobile=dataBean.getMobile();
					phone.setText(dataBean.getMobile());
					name.setText(dataBean.getRealname());
					edit_money.setText(money);
				}
			} else if (entity.getEventType() == UserPresenter.queryUserByPhone_success) {
				ByAlert.alert(entity.getData());
			}
		}
	}

}
